package br.mg.bhe.ftpobre.command;

import br.mg.bhe.ftpobre.command.facade.FileFacade;
import br.mg.bhe.ftpobre.fs.LocalFile;
import br.mg.bhe.ftpobre.util.LocalFileUtil;

/**
 * 
 * @author Aureliano
 */
public class OpenFileCommand implements ICommand {
	
	@Override
	public void execute() {
		if (this.canExecute()) {
			this.doAction();
		}
	}

	@Override
	public boolean canExecute() {
		LocalFile file = LocalFileUtil.getSelectedFile();
		return (
			(file != null) && 
			(!LocalFile.getUpFolder().equals(file)) && 
			(!file.isDirectory())
		);
	}

	private void doAction() {
		FileFacade.openFile();
	}
}